<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Model\CooperativeMenu;
use App\Request\Cooperative\CooperativeRoleSaveRequest;
use App\Service\Cooperative\CooperativeRoleService;
use Hyperf\Di\Annotation\Inject;

class CooperativeRoleController extends AbstractController
{

    /**
     * @Inject()
     * @var CooperativeRoleService
     */
    protected $cooperativeRoleService;

    /**
     * 角色列表
     * @OperationLog(event="获取角色列表",platform="cooperative")
     */
    public function index()
    {
        $index = $this->cooperativeRoleService->index([]);
        return $this->response->success($index);
    }

    /**
     * 获取所有角色
     * @OperationLog(event="获取所有角色",platform="cooperative")
     */
    public function all()
    {
        $all = $this->cooperativeRoleService->all([]);
        return $this->response->success($all);
    }

    /**
     * 新增/编辑角色
     * @OperationLog(event="新增/编辑角色",platform="cooperative")
     */
    public function save($id, CooperativeRoleSaveRequest $request)
    {
        $validated = $request->validated();
        $role = $this->cooperativeRoleService->save($id, $validated);
        return $this->response->success($role);
    }

    /**
     * 删除角色
     * @OperationLog(event="删除角色",platform="cooperative")
     */
    public function delete(int $id)
    {
        $this->cooperativeRoleService->delete($id);
        return $this->response->success();
    }

    /**
     * 获取角色对应的菜单
     * @OperationLog(event="获取角色对应的菜单",platform="cooperative")
     */
    public function menus(int $id)
    {
        $menus = $this->cooperativeRoleService->menus($id);
        return $this->response->success($menus);
    }

    /**
     * 获取全部合作商权限
     * @OperationLog(event="获取角色对应的菜单",platform="cooperative")
     */
    public function menuTree()
    {
        $menus = $this->cooperativeRoleService->menuTree();
        return $this->response->success($menus);
    }


}